package com.neusoft.yuejian12.yuejian_12.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.adapter.MyActOrderListAdapter;
import com.neusoft.yuejian12.yuejian_12.adapter.MyTrainOrderListAdapter;
import com.neusoft.yuejian12.yuejian_12.javabean.EnterActBean;
import com.neusoft.yuejian12.yuejian_12.listener.RetrofitListener;
import com.neusoft.yuejian12.yuejian_12.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyActOrderListActivity extends Activity  implements View.OnClickListener,RetrofitListener<List<EnterActBean>> {
    //声明
    private ImageView left;
    private int u_id;
    private RecyclerView recyclerView;
    private Button activityOrder_button,matchOrder_button,trainOrder_button;
    private MyActOrderListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_train_order_list);
        initViews();//初始化
       // initData();//点击事件处理
        initEvent();
        getMyActOrderlist();
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.my_order);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        left = (ImageView) findViewById(R.id.left);
        activityOrder_button= (Button) findViewById(R.id.activityOrder_button);
        matchOrder_button= (Button) findViewById(R.id.matchOrder_button);
        trainOrder_button= (Button) findViewById(R.id.trainOrder_button);
    }
    private void initEvent() {
        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        trainOrder_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new  Intent(MyActOrderListActivity.this,MyTrainOrderListActivity.class);
                startActivity(intent);
            }
        });
        matchOrder_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new  Intent(MyActOrderListActivity.this,MyMatchOrderListActivity.class);
                startActivity(intent);
            }
        });

    }
    void getMyActOrderlist(){
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("u_id", 0);
        UserModel userModel=new UserModel();
        userModel.getMyActOrderlist(u_id,this);
    }

    @Override
    public void onSuccess(List<EnterActBean> enterTrainBeen){
        adapter = new MyActOrderListAdapter(MyActOrderListActivity.this,enterTrainBeen);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail() {
        //showToast("网络发生错误");
    }
    @Override
    public void onClick(View view) {

    }

//    private void initData() {
//        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
//        u_id = sp.getInt("u_id", 0);
////             Log.d("we","u_id");
//
//        UserModel userModel = new UserModel();
//        //发送请求
//        Call<List<EnterActBean>> call = userModel.getMyActOrderlist
//                (u_id);
//        //2.处理结果
//        call.enqueue(new Callback<List<EnterActBean>>() {
//            @Override
//            public void onResponse(Call<List<EnterActBean>> call, Response<List<EnterActBean>> response) {
//                List<EnterActBean> data = (List<EnterActBean>) response.body();  //获取数据
//                recyclerView.setAdapter(new MyActOrderListAdapter(MyActOrderListActivity.this, data));
//            }
//
//            @Override
//            public void onFailure(Call<List<EnterActBean>> call, Throwable t) {
//
//            }
//
//        });
//
//    }
}

